package ctbu.edu.cn.teachersjpa.service;

import ctbu.edu.cn.teachersjpa.domain.Teachers;
import ctbu.edu.cn.teachersjpa.respository.TeachersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.lang.Integer.parseInt;

@Service
public class TeachersService {
    @Autowired
    private TeachersRepository teachersRepository;
    /**
     *
     * @param id 根据主键来查询
     * @return Teachers
     */
    public Teachers findById(Integer id){
        return teachersRepository.findById(id).orElse(null);
    }

    /**
     * 查询全部
     * @return
     */
    public List<Teachers> findAll(){
        return teachersRepository.findAll();
    }

    /**
     * 根据工号查询
     * @param worknumber
     * @return
     */
    public List<Teachers> findTeachersByWorknumber(String worknumber){
        return teachersRepository.findTeachersByWorknumber(worknumber);
    }

    /**
     * 根据姓名查询
     * @param name
     * @return
     */
    public List<Teachers> findByName(String name){
        return  teachersRepository.findByName(name);
    }


    /**
     * 插入数据
     * @param teachers
     * @return
     */
    public Teachers insert(Teachers teachers){
        teachersRepository.save(teachers);
        return teachers;
    }

    /**
     * 更新数据
     * @param teachers
     * @return
     */
    public Teachers update(Teachers teachers){
        teachersRepository.save(teachers);
        return teachers;
    }

    /**
     * 根据id来删除数据
     * @param id
     */
    public void delete(Integer id){
        teachersRepository.deleteById(id);
    }
    /**
     *
     */



}

